Skip to content

Conversation

@compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Nov 20, 2024

The PointerLike trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling layout_of in the trait system also causes cycles.

This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be derive()d for custom smart pointers, and we can trust that as a semver promise rather than risking library authors accidentally breaking it.

On the other hand, we may never expose PointerLike, but at least now the implementation doesn't invoke layout_of which could cause ICEs or cause cycles.

Right now for a PointerLike impl to be valid, it must be an ADT that is repr(transparent) and the non-1zst field needs to implement PointerLike. There are also some primitive impls for &T/ &mut T/*const T/*mut T/Box<T>.

@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 20, 2024
@compiler-errors
Copy link
Member Author

r? lcnr

@rustbot rustbot assigned lcnr and unassigned Nadrieril Nov 20, 2024
@lcnr
Copy link
Contributor

lcnr commented Nov 20, 2024

cc #102425 @nikomatsakis

this seems reasonable to me and r=me on the impl after nits, idk about the lang side here 😁 I agree with the backcompat concerns, I feel like layout cycles are something we can definitely solve in the solver

@compiler-errors
Copy link
Member Author

I added two FIXMEs.

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Nov 20, 2024

📌 Commit 94260bd has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2024
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Nov 20, 2024

📌 Commit 228068b has been approved by lcnr

It is now in the queue for this repository.

@bors bors merged commit fbed195 into rust-lang:master Nov 21, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants